package com.chaoyong.higo.adapter;

import java.util.ArrayList;
import java.util.List;

import com.chaoyong.higo.R;
import com.chaoyong.higo.bean.UserListBean.DataEntity.ListEntity;
import com.chaoyong.higo.utils.V;
import com.chaoyong.higo.utils.Values;
import com.lidroid.xutils.BitmapUtils;
import com.lidroid.xutils.HttpUtils;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.RecyclerView.ViewHolder;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

public class ProtailAdapter extends RecyclerView.Adapter<ProtailAdapter.ProViewHolder> {
	private Context context;
	private LayoutInflater inflater;
	private List<ListEntity> list = new ArrayList<ListEntity>();
	//private List<ListEntity> list;

	public ProtailAdapter(Context context, List<ListEntity> list) {
		super();
		this.context = context;
		this.list = list;
		inflater = inflater.from(context);
	}

	public void changeData(List<ListEntity> entity){
		this.list = entity;
		this.notifyDataSetChanged();
	}
	
	class ProViewHolder extends ViewHolder {
		private TextView name_tx, city_tx, ip_tx, count_tx, time_tx;
		private ImageView user_img;

		public ProViewHolder(View arg0) {
			super(arg0);
			user_img = (ImageView) arg0.findViewById(R.id.prouser_user_img);
			name_tx = (TextView) arg0.findViewById(R.id.prouser_name_tx);
			city_tx = (TextView) arg0.findViewById(R.id.prouser_city_tx);
			count_tx = (TextView) arg0.findViewById(R.id.prouser_count_tx);
			time_tx = (TextView) arg0.findViewById(R.id.prouser_time_tx);
			ip_tx = (TextView) arg0.findViewById(R.id.prouser_ip_tx);
		}

	}

	@Override
	public int getItemCount() {
		return list == null ? 0 : list.size();
	}

	@Override
	public void onBindViewHolder(ProViewHolder holder, int arg1) {
		String username = list.get(arg1).getUser_name();
		//holder.name_tx.setText(username.substring(0,3)+"****"+username.substring(7));
		//holder.name_tx.setText(username);
		if(TextUtils.isEmpty(username)){
			holder.name_tx.setText("");
		}else{
			//holder.name_tx.setText(username.substring(0,3)+"****"+username.substring(7));
			holder.name_tx.setText(username);
		}
		holder.city_tx.setText(list.get(arg1).getRegion());
		holder.ip_tx.setText(list.get(arg1).getIp());
		holder.count_tx.setText(list.get(arg1).getBuy_money());
		BitmapUtils utils = new BitmapUtils(context);
		String url = Values.BASE_IMAGE_URL + list.get(arg1).getUser_img();
		utils.display(holder.user_img, url);
	}

	@Override
	public ProViewHolder onCreateViewHolder(ViewGroup arg0, int arg1) {
		ProViewHolder holder = new ProViewHolder(inflater.inflate(R.layout.item_prodetail_user, arg0, false));

		return holder;
	}
}
